//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hl.sfzy.controller;

import com.hl.sfzy.entity.Article;
import com.hl.sfzy.service.ArticleService;
import com.hl.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping({"/article"})
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    public ArticleController() {
    }

    @PostMapping({"/add"})
    public Result add(@RequestBody Article article) throws Exception {
        this.articleService.add(article);
        return Result.success();
    }

    @PutMapping({"/edit"})
    public Result edit(@RequestBody Article article) {
        this.articleService.edit(article);
        return Result.success();
    }

    @DeleteMapping({"/remove/{id}"})
    public Result remove(@PathVariable Integer id) {
        this.articleService.remove(id);
        return Result.success();
    }

    @DeleteMapping({"/remove"})
    public Result removeBatch(Integer[] ids) {
        this.articleService.removeBatch(ids);
        return Result.success();
    }

    @GetMapping({"/find/{id}"})
    public Result findById(@PathVariable Integer id) {
        return Result.success(this.articleService.findById(id));
    }

    @GetMapping({"/find"})
    public Result findPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize, Article article) {
        return Result.success(this.articleService.findPage(pageNum, pageSize, article));
    }
}

